package com.mlk.score.service.impl;

import com.mlk.constant.EngConstant;
import com.mlk.core.component.page.Page;
import com.mlk.core.component.page.Pager;
import com.mlk.core.util.ServerResponse;
import com.mlk.score.mapper.EngInScoreMapper;
import com.mlk.score.po.EngInScore;
import com.mlk.score.po.EngScore;
import com.mlk.score.service.EngInScoreService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EngInScoreServiceImpl implements EngInScoreService {
    @Resource
    private EngInScoreMapper engInScoreMapper;
    @Override
    public ServerResponse findTotalScore(String openId) {
        return ServerResponse.ok(this.engInScoreMapper.findTotalScore(openId));
    }

    @Override
    @Page
    public Pager findTotalScoreDetail(EngScore score) {
        List<EngInScore> list = this.engInScoreMapper.findTotalScoreDetail(score);
        list.stream().forEach(e->{
            if(e.getNum()>0){
                e.setName(EngConstant.IN_SCORE_SOURCE_REF.getValue(e.getType()));
            }else {
                e.setName(EngConstant.OUT_SCORE_TARGET_REF.getValue(e.getType()));
            }
        });
        return Pager.adapt(list);
    }
}
